{% extends "default/base.html" %}
{% load i18n %}

{% block header %}

{% endblock %}

{% block content %}

<script type="text/javascript">
	$(document).ready(function() {
 
		$("#dialog_form_open").dialog({
			autoOpen: false,
			height: 520,
			width: 460,
			modal: true,
			position: 'center',
			resizable: false,
			draggable: false,
			overlay: {opacity: 0.9, background: "black"},
		});	
		
                /*		
		$('#create_item').click(function() {
			//		$('#dialog_form').dialog('open');
		});
                */
				
		$("#id_category").change(function () {
                    /*
                    categories= new Array();
		    $("#id_category option:selected").each(function () {
		    	categories.push($(this).val())
		    });
                    */
                    var categories = $(".form-stacked #id_category option[value!='']:selected").val();

                    $("#id_subcategory").empty();
                    $.post("{% url ajax_get_subcategories %}", { 'categories': categories }, function(data){
                         $(".form-stacked #id_subcategory").html(data);
                    });
	    })
	    .trigger('change');
	});
</script>
<ul class="breadcrumb">
 <li><a href="{% url market_home %}">{% trans "Home" %}</a><span class="divider">/</span></li>
 <li><a href="{% url market_buy %}">{% trans "Buy" %}</a><span class="divider">/</span></li>
 <li class="active">{% trans "Wish List" %}</li>
</ul>

<div class="sidebar">
 <div class="well">
  <h5>Post Your Wish List Item</h5>
{% if user.is_authenticated %}
   <ul>
    <li>
          <button data-controls-modal="modal-from-dom" data-backdrop="true" data-keyboard="true" id="create_item" class="btn primary">Post Wish List Item</button>
    </li>
   </ul>

{% else %}

  <ul>
	<li>
      	<a href="{% url market_buy_signup %}" class="btn primary">Please Register</a>
</li>
</ul>



{% endif %}
  </div>
</div>

	  <div id="modal-from-dom" class="modal hide fade">
            <div class="modal-header">
              <a href="#" class="close">&times;</a>
              <h3>Post Your Wish List Item</h3>
            </div>
            <div class="modal-body">
        	<form class="form-stacked" id="dialog_form" action="{% url post_wish_list_item %}" method="POST" name="form">
		{{ form.as_p }}
		<button type="submit" class="btn primary">{% trans 'Save Item' %}</button> 
            	</form>
		</div>
            <div class="modal-footer">
	   </div>
          </div>
 
<div class="span12">
<h2>{% trans "Wish List" %}</h2>

<p>Find the Coin you've always looked for with our marketplace of dealers. Post Your Wish List For all the dealers to see.
{% if not user.is_authenticated %}
{% trans "You must be logged in to post in the wish list. " %}<a href="{% url market_buy_login %}?next={% url buy_wish_list %}">{% trans "Login Here" %}</a>
{% endif %}
</p>

{% if wish_list %}
<table class="zebra-striped">
<thead>
<tr>
	<th><b>{% trans "Posted By" %}</b></th>
		<th><b>{% trans "Category" %}</b></th>
		<th><b>{% trans "Subcategory" %}</b></th>
		<th><b>{% trans "Ideal Price" %}</b></th>
		<th><b>{% trans "Posted On" %}</b></th>
		<th><b>{% trans "Description" %}</b></th>
</tr>
<tbody>
{% for item in wish_list %}	
<tr>
  <td>	{% if item.public %}
	{{ item.posted_by }}
	{% else %}
	*******
	{% endif %}
 </td>
 <td>{{ item.category.name }}
</td>
		<td>{% if item.subcategory %}{{ item.subcategory.name }}{% else %} --- {% endif %}</td>
		<td class="IdealPrice">${{ item.ideal_price }}</td>
		<td>{{ item.posted_on|date:"d F Y H:i" }}</td>
		<td>{{ item.description.capitalize|safe }}</td>
</tr>
{% endfor %}
</tbody>
</table>

{% else %}
<div class="alert-message warning">{% trans "There are no Wish List items posted yet..." %}</div>
{% endif %}

{% comment %}
{% if user.is_authenticated %}
<div id="create_item" class="btn primary">{% trans "Post your item" %}</div>
{% endif %}

	<form class="form-stacked" id="dialog_form" action="{% url post_wish_list_item %}" method="POST" name="form">
		{{ form.as_p }}
		<button type="submit" class="btn primary">{% trans 'Save Item' %}</button> 
	</form>
</div>
{% endcomment %}
</div>

{% endblock %}
